package hwOne1;


public class MathLg {
    public static void main(String[] args) {
//        int result = lg(10);
        int[] data = {1, 2, 2, 5, 6};
        histogram(data, 3);
    }
    /**
     * 作业 1.1.14
     */
    public static int lg(int N) {
        if (N <= 0) {
            throw new IllegalArgumentException("N must be greater than 0");
        }

        int x = 0;

        while (N > 1) {
            N = N / 2;
            x += 1;
        }
        System.out.println(x);
        return x;
    }

    /**
     * 作业 1.1.15
     * @param a
     * @param M
     * @return
     */
    public static void histogram(int[] a, int M) {
        int[] store = new int[M];
        for (int i = 0; i < M; i++) {
            int mem = 0;
            int count = 0;
            for (int j = 0; j < a.length; j++) {
                int a1 = a[j];
                if (a1 == i) {
                    count++;
                }
            }
            mem = count;
            store[i] = mem;
        }

        for (int element : store) {
            System.out.println(element);
        }
    }
}
